﻿using MathNet.Numerics;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearRegression;

namespace UtilZ.Dotnet.MathNetEx.LinearAlgebra
{
    /// <summary>
    /// Polynomial拟合扩展类
    /// </summary>
    public class PolynomialEx
    {
        /// <summary>
        /// Least-Squares fitting the points (x,y) to a k-order polynomial y : x -> p0 + p1*x + p2*x^2 + ... + pk*x^k
        /// </summary>
        public static Polynomial Fit(double[] x, double[] y, int order, DirectRegressionMethod method = DirectRegressionMethod.QR)
        {
            var coefficients = FitEx.Polynomial(x, y, order, method);
            return new Polynomial(coefficients);
        }

    }

}
